
$(function() {
	$(".nav-ul li").eq(4).addClass("cur");
    if ($(".form-inline div").hasClass('form-more')) {
        $('.btn-more').show()
    }
    $('.btn-clear-form').click(function () {
        $('.form-inline input').val('')
    })
	 
	query(1);
	
	$('#pageNum').dropdown();
	$('#dropdown').on('shown.bs.dropdown', function () {
	     $('.dropdown-menu li').click(function () {
	         var str = $(this).children('a').html();
	         var size = $(this).children('a').children('label').text();
	         str += '<span class="caret"></span>';
	         $("#pageNum").html(str);
	         
	         query(1);
	     })
	 });
	
	 upLoadAllData();
	
     upLoadIncData();
     
	 evalResultOper();
	 
});

function jumpQuery(){
	var page = $("#jump_page").val();
	var reg = /^\+?[1-9][0-9]*$/;//判断是否为正整数 
    var flag = reg.test(trim(page));
    if(!flag){
    	layer.alert("请输入正整数！", {
			icon : 3,
			offset: '100px'
		});
    }else{
    	var totalPages = $("#total_pages").text();
    	if(parseInt(page) > parseInt(totalPages)){
    		layer.alert("跳转页数不能超过总页数！", {
    			icon : 3,
    			offset: '100px'
    		});
    	}else{
    		query(page);
    	}
    }
}

function query(page){
	layer.load(4);
	$.ajax({
		type : "POST",
		url :  "evalResultInfo/getEvalPassEnterpriseInfo",
		data : {
			"currentPage" : page,
			"enterprise_name" : $("#enterprise_name").val(),
			"registered_address" : $("#registered_address").val(),
			"evalNum" : $("#evalNum").val(),
			"production_unit" : $("#production_unit").val(),
			"apply_business" : $("#apply_business").val(),
			"userId" : $("#userId").val(),
			"pageSize" : $("#pageNum").children('strong').text()
		},
		dataType : "json",
		success : function(data) {
			layer.closeAll();
			if (data.flag) {
				var tread = data.datas;
				insertInfoTpl(tread, $('#tread'), $('#treadTpl'));
				var currentPage = data.currentPage;
				var totalPages = data.totalPages;
				var totalData = data.totalData;
				$("#total_data").text(totalData);
				$("#total_pages").text(totalPages);
				var options = {
					currentPage : currentPage, // 当前的请求页面。
					totalPages : totalPages, // 一共多少页。
					size : "normal", // 应该是页眉的大小。
					bootstrapMajorVersion : 3, // bootstrap的版本要求。
					alignment : "right",
					numberOfPages : 5, // 一页显示几个按钮
					itemTexts : function(type, page, current) { // 如下的代码是将页眉显示的中文显示我们自定义的中文。
						switch (type) {
						case "first":
							return "首页";
						case "prev":
							return "上一页";
						case "next":
							return "下一页";
						case "last":
							return "末页";
						case "page":
							return page;
						}
					},
					tooltipTitles : function(type, page, current) { // 提示框，当鼠标放上去给提示
						switch (type) {
						case "first":
							return "首页";
						case "prev":
							return "上一页";
						case "next":
							return "下一页";
						case "last":
							return "末页";
						}
					},
					onPageClicked : function(event, originalEvent, type, page) {
						layer.load(4);
						$.ajax({
							type : "POST",
							url :  "evalResultInfo/getEvalPassEnterpriseInfo",
							data : {
								"currentPage" : page,
								"enterprise_name" : $("#enterprise_name").val(),
								"registered_address" : $("#registered_address").val(),
								"evalNum" : $("#evalNum").val(),
								"production_unit" : $("#production_unit").val(),
								"apply_business" : $("#apply_business").val(),
								"userId" : $("#userId").val(),
								"pageSize" : $("#pageNum").children('strong').text()
							},
							dataType : "json",
							success : function(data) {
								if (data.flag) {
									layer.closeAll();
									var tread = data.datas;
									insertInfoTpl(tread, $('#tread'),$('#treadTpl'));
								}
							},
							error : function(data) {
								layer.closeAll();
							}
						});
					}
				}
				$('#pageLimit').bootstrapPaginator(options);
			}
		},
		error : function(data) {
			layer.closeAll();
		}
	});
}

function linkPage(id,apply_business,evalNum) {
	var userId = $("#userId").val();
	var htmlSrc = {
		house_node_num : 'evalResultQueryHouse?evalNum='+evalNum+'&apply_business='+apply_business+'&userId='+userId,
		link_num : 'evalResultQueryLink?evalNum='+evalNum+'&userId='+userId,
		contacts_info : 'evalResultQueryContact?evalNum='+evalNum+'&userId='+userId
	}
	var iframeSrc = '';
	if (id == 'house_node_num') {
		iframeSrc = htmlSrc.house_node_num;
	}else if(id == 'link_num'){
		iframeSrc = htmlSrc.link_num;
	}else if(id == 'contacts_info'){
		iframeSrc = htmlSrc.contacts_info;
	}
	var iframeStr = '<iframe src=' + iframeSrc+ ' frameborder="0" ></iframe>';
	$('#modalBody').html(iframeStr);
}

function eval_result() {
	$("#evalNumHidden").val('');
	$("#enterprise_name_oper").val('');
	$("#apply_business_oper").val('');
	$("#registered_address_oper").val('');
	$("#handleInfo_oper").val('');
	$("#contacts_oper").val('');
	$("#tel_oper").val('');
	$("#moveTle_oper").val('');
	$("#eMail_oper").val('');
	$("#production_unit_oper").val('');

	var coverList = $('#coverInfoList')
    var houseList = $('#houseInfoList');
	
	coverList.empty();
	houseList.empty();
}

function result_del(evalNum){
	layer.load(4);
	$.ajax({
		type : "POST",
		url : "evalResultInfo/del",
		data : {
			"evalNum" : evalNum
		},
		dataType : "json",
		success : function(data) {
			layer.closeAll();
			query(1);
			alert(data.msg);
		},
		error : function(data) {
			layer.closeAll();
		}
	});
}

function result_edit(evalNum){
	layer.load(4);
	$.ajax({
		type : "POST",
		url : "evalResultInfo/query",
		data : {
			"evalNum" : evalNum
		},
		dataType : "json",
		success : function(data) {
			layer.closeAll();
			if (data.flag) {
				$("#evalNumHidden").val(evalNum);
				
				var datas = data.datas
				var masterInfo = datas.masterInfo;
				var linkInfo = datas.linkInfo;
				var houseInfo = datas.houseInfo;
				
				$("#enterprise_name_oper").val(masterInfo.enterprise_name);
				$("#apply_business_oper").val(masterInfo.apply_business);
				$("#registered_address_oper").val(masterInfo.registered_address);
				$("#handleInfo_oper").val(masterInfo.handleInfo);
				$("#contacts_oper").val(masterInfo.contacts);
				$("#tel_oper").val(masterInfo.tel);
				$("#moveTle_oper").val(masterInfo.moveTle);
				$("#eMail_oper").val(masterInfo.eMail);
				$("#production_unit_oper").val(masterInfo.production_unit);
				
				var coverList = $('#coverInfoList');
		    	coverList.empty();
		    	
			    if(linkInfo != null){
			    	for(var i =0 ; i < linkInfo.length ; i++){
			    		var link = linkInfo[i];
			    		var link_province = initProvice();
			    		var link_type_id = "link_type_"+i;
			    		var link_province_id = "link_province_"+i;
			    		var coverTr = '<tr>'+
							    	        '<td>'+
							    	        '  <select id='+link_type_id+' name="link_type" class="form-control">'+
							    	        '    <option value="联通">联通</option>'+
							    	        '    <option value="移动">移动</option>'+
							    	        '    <option value="电信">电信</option>'+
							    	        '    <option value="其他">其他</option>'+
							    	        '  </select>'+
							    	        '</td>'+
							    	        '<td>'+
							    	        '  <input name="link_bandwidth" type="text" class="form-control input-sm" value='+link.link_bandwidth+'></input>'+
							    	        '</td>'+
							    	        '<td>'+
							    	        '  <select name="link_province" id='+link_province_id+' class="form-control">'+
							    	               link_province +
							    	        '  </select>'+
							    	        '</td>'+
							    	        '<td>'+
							    	        '  <input type="text" class="form-control input-sm" value='+link.house_name+'></input>'+
							    	        '</td>'+
							    	        '<td class="delete">'+
							    	        '  -'+
							    	        '</td>'+
							    	      '</tr>';
		    	      coverList.append(coverTr);
		    	      
		    	      $("#"+link_type_id).val(link.link_type);
		    	      $("#"+link_province_id).val(link.link_province);
			    	}
			    }
				
			    var houseList = $('#houseInfoList');
			    houseList.empty();
			    
			    if(houseInfo != null){
			    	for(var i = 0 ; i < houseInfo.length ; i++){
			    		var house = houseInfo[i];
			    		
			    		var house_province = initProvice();
			    		
			    		var house_province_id = "house_province_"+i;
			            var house_city_id = "house_city_"+i;
			        	var houserTr = '<tr>'+
			            '<td>'+
			            '  <select id='+house_province_id+' onchange="changeProvince(this,'+i+')" class="form-control">'+
			            		house_province +
			            '  </select>'+
			            '</td>'+
			            '<td>'+
			            '  <select id='+house_city_id+' class="form-control"/></select>'+
			            '</td>'+
			            '<td>'+
			            '  <input type="text" class="form-control input-sm" value='+house.house_name+'></input>'+
			            '</td>'+
			            '<td>'+
			            '  <input type="text" class="form-control input-sm" value='+house.house_add+'></input>'+
			            '</td>'+
			            '<td class="delete">'+
			            '  -'+
			            '</td>'+
			          '</tr>';
			          houseList.append(houserTr);
			          
			          var obj = new Object();
			          obj.value = house.house_province;
			          changeProvince(obj,i);
			          
			          $("#"+house_province_id).val(house.house_province);
		    	      $("#"+house_city_id).val(house.house_city);
			    	}
			    }
			}
		},
		error : function(data) {
			layer.closeAll();
		}
	});
}

function evalResultOper(){
	var coverList = $('#coverInfoList')
    var houseList = $('#houseInfoList');
	
	coverList.empty();
	houseList.empty();
	
	var link_province = initProvice();
    var coverTr = '<tr>'+
      '<td>'+
      '  <select name="link_type" class="form-control">'+
      '    <option value="联通">联通</option>'+
      '    <option value="移动">移动</option>'+
      '    <option value="电信">电信</option>'+
      '    <option value="其他">其他</option>'+
      '  </select>'+
      '</td>'+
      '<td>'+
      '  <input name="link_bandwidth"  type="text" class="form-control input-sm" />'+
      '</td>'+
      '<td>'+
      '  <select name="link_province" id="link_province" class="form-control">'+
             link_province +
      '  </select>'+
      '<td>'+
      '  <input type="text" class="form-control input-sm" />'+
      '</td>'+
      '</td>'+
      '<td class="delete">'+
      '  -'+
      '</td>'+
    '</tr>';
    coverList.append(coverTr)
    
    $('#addCoverInfo').on('click', function(){
      var link_province = initProvice();
      var coverTr = '<tr>'+
        '<td>'+
        '  <select name="link_type" class="form-control">'+
        '    <option value="联通">联通</option>'+
        '    <option value="移动">移动</option>'+
        '    <option value="电信">电信</option>'+
        '    <option value="其他">其他</option>'+
        '  </select>'+
        '</td>'+
        '<td>'+
        '  <input name="link_bandwidth" type="text" class="form-control input-sm" />'+
        '</td>'+
        '<td>'+
        '  <select name="link_province" id="link_province" class="form-control">'+
               link_province +
        '  </select>'+
        '</td>'+
        '<td>'+
        '  <input type="text" class="form-control input-sm" />'+
        '</td>'+
        '<td class="delete">'+
        '  -'+
        '</td>'+
      '</tr>';
      coverList.append(coverTr)
    })
    
    var house_province = initProvice();
    var houserTr = '<tr>'+
        '<td>'+
        '  <select id="house_province" onchange="changeProvince(this,0)" class="form-control">'+
        		house_province +
        '  </select>'+
        '</td>'+
        '<td>'+
        '  <select id="house_city_0" class="form-control"/></select>'+
        '</td>'+
        '<td>'+
        '  <input name="house_name" type="text" class="form-control input-sm" />'+
        '</td>'+
        '<td>'+
        '  <input name="house_add" type="text" class="form-control input-sm" />'+
        '</td>'+
        '<td class="delete">'+
        '  -'+
        '</td>'+
      '</tr>';
      houseList.append(houserTr)
      
      var obj = new Object();
      obj.value = '110000';
      changeProvince(obj,'0');
    
    var house_index = 1;
    $('#addHouseInfo').on('click', function(){
    	house_index++;
    	var house_province = initProvice();
        var house_city = "house_city_"+house_index;
    	var houserTr = '<tr>'+
        '<td>'+
        '  <select id="house_province" onchange="changeProvince(this,'+house_index+')" class="form-control">'+
        		house_province +
        '  </select>'+
        '</td>'+
        '<td>'+
        '  <select id='+house_city+' class="form-control"/></select>'+
        '</td>'+
        '<td>'+
        '  <input type="text" class="form-control input-sm" />'+
        '</td>'+
        '<td>'+
        '  <input type="text" class="form-control input-sm" />'+
        '</td>'+
        '<td class="delete">'+
        '  -'+
        '</td>'+
      '</tr>';
      houseList.append(houserTr);
      
      var obj1 = new Object();
      obj1.value = '110000';
      changeProvince(obj1,house_index);
      
    })
    
    $('#coverInfoList ').on('click','.delete', function(){
      $(this).parent('tr').remove()
    })
    $('#houseInfoList').on('click', '.delete', function(){
      $(this).parent('tr').remove()
    })
}

function result_oper_submit(){
	 
 	var link_info = '';
 	$('#coverInfoList tr').each(function() {
			var link_type = $(this).find('td').eq(0).find("select").val()
			var link_bandwidth = $(this).find('td').eq(1).find("input:text").val();
			var link_province =$(this).find('td').eq(2).find("option:selected").text()
			var house_name = $(this).find('td').eq(3).find("input:text").val();
			link_info +=link_type+"-"+link_bandwidth+"-"+link_province+"-"+house_name+"@";
		});  
 	
 	var house_info = '';
 	$('#houseInfoList tr').each(function() {
			var house_province = $(this).find('td').eq(0).find("option:selected").text();
			var house_city = $(this).find('td').eq(1).find("select").val()
			var house_name = $(this).find('td').eq(2).find("input:text").val();
			var house_add = $(this).find('td').eq(2).find("input:text").val();
			house_info +=house_province+"-"+house_city+"-"+house_name+"-"+house_add+"@";
		});  
 	
 	var evalNum = $("#evalNumHidden").val();
 	layer.load(4);
 	if(evalNum != ''){
 		$.ajax({
 			type : "POST",
 			url : "evalResultInfo/edit",
 			data : {
 				"evalNum" : evalNum,
 				"enterprise_name" : $("#enterprise_name_oper").val(),
 				"apply_business" : $("#apply_business_oper").val(),
 				"registered_address" : $("#registered_address_oper").val(),
 				"handleInfo" : $("#handleInfo_oper").val(),
 				"contacts" : $("#contacts_oper").val(),
 				"tel" : $("#tel_oper").val(),
 				"moveTle" : $("#moveTle_oper").val(),
 				"eMail" : $("#eMail_oper").val(),
 				"production_unit" : $("#production_unit_oper").val(),
 				"link_info" : link_info,
 				"house_info" : house_info
 			},
 			dataType : "json",
 			success : function(data) {
 				layer.closeAll();
 				if (data.flag) {
 					alert(data.msg);
 					query(1);
 					$('#closeWin').click();
 				} else {
 					alert(data.msg);
 				}
 			},
 			error : function(data) {
 				layer.closeAll();
 			}
 		});
 	}else{
 		$.ajax({
 	 		type : "POST",
 	 		url : "evalResultInfo/save",
 	 		data : {
 	 			"enterprise_name" : $("#enterprise_name_oper").val(),
 	 			"apply_business" : $("#apply_business_oper").val(),
 	 			"registered_address" : $("#registered_address_oper").val(),
 	 			"handleInfo" : $("#handleInfo_oper").val(),
 	 			"contacts" : $("#contacts_oper").val(),
 	 			"tel" : $("#tel_oper").val(),
 	 			"moveTle" : $("#moveTle_oper").val(),
 	 			"eMail" : $("#eMail_oper").val(),
 	 			"production_unit" : $("#production_unit_oper").val(),
 	 			"link_info" : link_info,
 	 			"house_info" : house_info
 	 		},
 	 		dataType : "json",
 	 		success : function(data) {
 	 			layer.closeAll();
 	 			if (data.flag) {
 	 				alert(data.msg);
 	 				query(1);
 	 				$('#closeWin').click();
 	 			} else {
 	 				alert(data.msg);
 	 			}
 	 		},
 	 		error : function(data) {
 	 			layer.closeAll();
 	 		}
 	 	});
 	}
}

function initProvice(){
	var province = '';
	$.ajax({
		type:"POST",
		url:"province/getList",
		async:false,
		dataType:'json',
		success:function(result){
			if(result){
				for(var i=0; i<result.length; i++){
					province += '<option value="'+result[i].province+'">'+result[i].province+'</option>';
				}
			}
		}
	});
	return province;
}

function changeProvince(obj,index){
	$.ajax({
		type:"POST",
		async:false,
		url:"cities/getByProvince",
		data: {
			'province' : obj.value
		},
		async:false,
		dataType:'json',
		success:function(result){
			if(result){
				var house_city = $("#house_city_"+index);
				house_city.empty();
				var str = '';
				for(var i=0; i<result.length; i++){
					str += '<option value="'+result[i].city+'">'+result[i].city+'</option>';
				}
				house_city.append(str);
			}
		}
	});
}

function upLoadAllData(){
	layui.use('upload', function () {
	      var $ = layui.jquery, upload = layui.upload;
	      // 多文件列表示例
	      var demoListView = $('#importList')
	      var uploadListIns = upload.render({
	        elem: '#chooseFile',
	        url: 'evalResultInfo/importData',
	        accept: 'file',
	        multiple: true,
	        auto: false,
	        bindAction: '#chooseFileAction',
	        choose: function (obj) {
	          $('#fileList').css('display', 'block');
	          // 读取本地文件
	          obj.preview(function (index, file, result) {
	            $('#importList').find('tr').remove()
	            var tr = $(['<tr id="upload-' + index + '">',
	                     '<td>' + file.name + '</td>',
	                     '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>',
	                     '<td>等待上传</td>',
	                     '</tr>'].join(''));
	            demoListView.append(tr);
	          });
	        },
	        before : function(){
	        	layer.load(1);
	        },
	        done: function (res, index, upload) {
	        	layer.closeAll('loading');
	            if (res.flag) { // 上传成功
	              var tr = demoListView.find('tr#upload-' + index)
	                , tds = tr.children();
	              tds.eq(2).html('<span style="color: #5FB878;">导入成功</span>');
	              tds.eq(3).html(''); // 清空操作
	              // return delete this.files[index]; //删除文件队列已经上传成功的文件
	            }else{
	               var filePath = res.filePath;
	               var fileName = res.fileName;
	               var tr = demoListView.find('tr#upload-' + index)
	                 , tds = tr.children();
	               tds.eq(2).html('<span style="color: #5FB878;">导入失败</span><em>【<a style="color:red" href="evalResultInfo/downFiles?fileName='+fileName+'&type=view">查看</a>】 </em>');
	               tds.eq(3).html(''); // 清空操作
	            }
	            // this.error(index, upload);
	          },
	          error: function (index, upload) {
	            var tr = demoListView.find('tr#upload-' + index)
	              , tds = tr.children();
	            tds.eq(2).html('<span style="color: #FF5722;">导入失败</span>');
	            tds.eq(3).find('.demo-reload').removeClass('layui-hide'); // 显示重传
	          }
	      })
	    })
}

function upLoadIncData(){
	layui.use('upload', function () {
	      var $ = layui.jquery, upload = layui.upload;
	      // 多文件列表示例
	      var demoListView = $('#importIncList')
	      var uploadListIns = upload.render({
	        elem: '#chooseIncFile',
	        url: 'evalResultInfo/importIncData',
	        accept: 'file',
	        multiple: true,
	        auto: false,
	        bindAction: '#chooseIncFileAction',
	        choose: function (obj) {
	          $('#fileIncList').css('display', 'block');
	          // 读取本地文件
	          obj.preview(function (index, file, result) {
	            $('#importIncList').find('tr').remove()
	            var tr = $(['<tr id="upload-' + index + '">',
	                     '<td>' + file.name + '</td>',
	                     '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>',
	                     '<td>等待上传</td>',
	                     '</tr>'].join(''));
	            demoListView.append(tr);
	          });
	        },
	        before : function(){
	        	layer.load(1);
	        },
	        done: function (res, index, upload) {
	        	layer.closeAll('loading');
	            if (res.flag) { // 上传成功
	              var tr = demoListView.find('tr#upload-' + index)
	                , tds = tr.children();
	              tds.eq(2).html('<span style="color: #5FB878;">导入成功</span>');
	              tds.eq(3).html(''); // 清空操作
	              // return delete this.files[index]; //删除文件队列已经上传成功的文件
	            }else{
	               var filePath = res.filePath;
	               var fileName = res.fileName;
	               var tr = demoListView.find('tr#upload-' + index)
	                 , tds = tr.children();
	               tds.eq(2).html('<span style="color: #5FB878;">导入失败</span><em>【<a style="color:red" href="evalResultInfo/downFiles?fileName='+fileName+'&type=view">查看</a>】 </em>');
	               tds.eq(3).html(''); // 清空操作
	            }
	            // this.error(index, upload);
	          },
	          error: function (index, upload) {
	            var tr = demoListView.find('tr#upload-' + index)
	              , tds = tr.children();
	            tds.eq(2).html('<span style="color: #FF5722;">导入失败</span>');
	            tds.eq(3).find('.demo-reload').removeClass('layui-hide'); // 显示重传
	          }
	      })
	    })
}

function importData(type){
	if(type == 1){
		$("#importList").empty();
	}else{
		$("#importIncList").empty();
	}
}

function upload_report(evalNum){
	
	var demoListView = $('#demoList')
	demoListView.empty();
	
	var userAuthority = $("#userAuthority").val();
	if(userAuthority == 4){//企业账号,只让看评测报告
		
		$("#uploadfile_span").hide();
		$("#upload_file_submit").css("display","none");
		
		layer.load(4);
		$.ajax({
			type : "POST",
			async: false,
			url : "evalResultInfo/query",
			data : {
				"evalNum" : evalNum
			},
			dataType : "json",
			success : function(data) {
				layer.closeAll();
				if (data.flag) {
					var masterInfo = data.datas.masterInfo;
					var evaluation_report = masterInfo.evaluation_report;
					var evaluation_report_size = masterInfo.evaluation_report_size;
					if(evaluation_report != null){
						$('#demoList').find('tr').remove()
					       var tr = '<tr>'+
					         '<td>' + evaluation_report + '</td>'+
					         '<td>' + evaluation_report_size + 'kb</td>'+
					         '<td><em>'+
			                     '【<a style="color: #5FB878;" href="evalResultInfo/downFiles?fileName='+evaluation_report+'&type=report">下载</a>】'+
		                     '</td>'+
					         '</tr>';
				       demoListView.append(tr);
					}
				} else {
				}
			},
			error : function(data) {
				layer.closeAll();
			}
		});
	}else if(userAuthority == 5){//超级管理员
		layer.load(4);
		$.ajax({
			type : "POST",
			async: false,
			url : "evalResultInfo/query",
			data : {
				"evalNum" : evalNum
			},
			dataType : "json",
			success : function(data) {
				layer.closeAll();
				if (data.flag) {
					var masterInfo = data.datas.masterInfo;
					var evaluation_report = masterInfo.evaluation_report;
					var evaluation_report_size = masterInfo.evaluation_report_size;
					if(evaluation_report != null){
						$('#demoList').find('tr').remove()
					       var tr = '<tr>'+
					         '<td>' + evaluation_report + '</td>'+
					         '<td>' + evaluation_report_size + 'kb</td>'+
					         '<td>已上传<em>'+
			                     '【<a style="color: #5FB878;" href="evalResultInfo/downFiles?fileName='+evaluation_report+'&type=report">下载</a>】'+
			                     "【<a style='color: #5FB878;' href=\"javascript:report_del('"+evalNum+"')\">删除</a>】 </em>"+
		                     '</td>'+
					         '</tr>';
				       demoListView.append(tr);
					}
				} else {
				}
			},
			error : function(data) {
				layer.closeAll();
			}
		});
		var upload_file = $('#uploadfile')
	    upload_file.on('change', function (e) {
	      // e.currentTarget.files 是一个数组，如果支持多个文件，则需要遍历
	      var name = e.currentTarget.files[0].name;
	      var size = e.currentTarget.files[0].size;
	      $('#fileList_upload').css('display', 'block')
	      $('#demoList').find('tr').remove()
	       var tr = '<tr>'+
	         '<td>' + name + '</td>'+
	         '<td>' + (size / 1014).toFixed(1) + 'kb</td>'+
	         '<td>等待上传</td>'+
	         '</tr>';
	       demoListView.append(tr);
	    });

	    $('#upload_file_submit').on('click', function(){
	      layer.load(4);
	      $("#batchImportForm").ajaxSubmit({   
		        url:"evalResultInfo/uploadFile",   
		        type:"post",   
		        enctype:"multipart/form-data",   
		        contentType: "application/x-www-form-urlencoded; charset=utf-8",   
		        data : {
		        	"evalNum" : evalNum
		        },
		        dataType:"json",   
		        success: function(data){
		            layer.closeAll('loading');
		            if(data.flag){
		            	$('#demoList').find('tr').remove()
		            	var demoListView = $('#demoList');
		                var tr = '<tr>'+
		                  '<td>' + data.fileName + '</td>'+
		                  '<td>' + data.fileSize + 'kb</td>'+
		                  '<td>上传成功<em>'+
		                     '【<a style="color: #5FB878;" href="evalResultInfo/downFiles?fileName='+data.fileName+'&type=report">下载</a>】'+
		                     "【<a style='color: #5FB878;' href=\"javascript:report_del('"+evalNum+"')\">删除</a>】 </em>"+
		                  '</td>'+
		                  '</tr>';
		                demoListView.append(tr);
		            }
		        },   
		        error: function() {   
		            alert('error');  
		        }   
		    });
	      
	    })
	}
}

function report_del(evalNum){
	layer.load(4);
	$.ajax({
		type : "POST",
		url : "evalResultInfo/reportDel",
		data : {
			"evalNum" : evalNum
		},
		dataType : "json",
		success : function(data) {
			layer.closeAll();
			alert(data.msg);
			if (data.flag) {
				$('#demoList').empty();
			} else {
			}
		},
		error : function(data) {
			layer.closeAll();
		}
	});
}

function exportData(){
	layer.load(4);
	$.ajax({
		type : "POST",
		url : "evalResultInfo/exportData",
		data : {},
		dataType : "json",
		success : function(data) {
			layer.closeAll();
			if (data.flag) {
				var url = "evalResultInfo/downExportFiles?path="+ data.path;
				window.location.href = url;
			} else {
				alert(data.msgs);
			}
		},
		error : function(data) {
			layer.closeAll();
		}
	});
}
/**
 * [insertInfoTpl 插入 html信息]
 * 
 * @param {[type]}
 *            data [渲染所需的数据]
 * @param {[type]}
 *            dom [加入页面中的哪个DOM节点]
 * @return {[type]} [description]
 */
function insertInfoTpl(data, dom, tpl) {
	dom.empty();
    var infoTpl = tpl.html()
    var compiled = _.template(infoTpl)
    var html = ''
    	
	var columnArray = new Array();	
    
    _.forEach(data, function (item, index) {
        item.index = index + 1
        // console.log(item, index)
        html += compiled(item)
        
        var map = {};
        map['userAuthority'] = $("#userAuthority").val();
        map['evalNum'] = item.evalNum;
        columnArray.push(map)
    })
    dom.append($(html))
    for(var i=0; i<columnArray.length; i++){
    	setBtnShow(columnArray[i].userAuthority,columnArray[i].evalNum);
    }
}

function setBtnShow(userAuthority,evalNum){
	if(userAuthority == 4){
		$('#result_oper_th').removeAttr('style');
		$('#eval_result_report_td_'+evalNum).removeAttr('style');
		$('#eval_result_report_'+evalNum).removeAttr('style');
	}
	if(userAuthority == 5){
		$('#result_oper_button').removeAttr('style');
		$('#result_oper_th').removeAttr('style');
		$('#eval_result_report_td_'+evalNum).removeAttr('style');
		$('#eval_result_report_'+evalNum).removeAttr('style');
		$('#eval_result_edit_'+evalNum).removeAttr('style');
		$('#eval_result_del_'+evalNum).removeAttr('style');
	}
}

function filter(name){
	if(name == null || name == "null" || name == undefined){
		return "";
	}else{
		return name
	}
}

function trim(str){ 
    return str.replace(/(^\s*)|(\s*$)/g, ""); 
}
String.prototype.endWith = function(s){ 
    if(s == null || s == "" || this.length == 0 || s.length > this.length)
        return false; 
    if(this.substring(this.length-s.length) == s) 
        return true; 
    else 
        return false; 
    return true; 
}